from rest_framework.views import APIView
from rest_framework.response import Response
from .sers import *


class StaffView(APIView):
    def get(self, request):
        queryset = Staff.objects.all()
        ser = StaffSerializer(queryset, many=True)

        return Response(ser.data)

    def put(self, request):
        # 更新主任
        id = request.data.get("id")
        Staff.objects.filter(id=id).update(gang_id=2)
        return Response({"msg": "晋升成功"})


class BusinessView(APIView):

    def get(self, request):
        queryset = Business.objects.all()
        ser = BusinessSerializer(queryset, many=True)
        return Response(ser.data)

    def put(self, request):
        id = request.data.get("id")
        money = request.data.get("money")

        Business.objects.filter(id=id).update(money=money)

        return Response({"msg": "添加成功"})
